package com.java.design.observer.java_build_in;

import com.java.design.observer.customer.Display;

import java.util.Observable;
import java.util.Observer;

/**
 * @author Tony
 */
public class CurrentConditionsDisplayJava implements Observer, Display {

    private Observable observable;

    private float temp;

    private float humidity;

    public CurrentConditionsDisplayJava(Observable observable){
        this.observable = observable;
        observable.addObserver(this);
    }

    @Override
    public void display() {
        System.out.println("current conditions: " + temp +"F degrees and " + humidity + "% humidity");
    }

    @Override
    public void update(Observable o, Object arg) {
        if(o instanceof WeatherDataJava){
            WeatherDataJava weatherDataJava = (WeatherDataJava) o;
            this.temp = weatherDataJava.getTemp();
            this.humidity = weatherDataJava.getHumidity();
           display();
        }
    }
}
